import { BASE_URL, TIMEOUT } from './request/config';
import HRRequest from './request';

const hrRequest = new HRRequest({
  baseURL: BASE_URL,
  timeout: TIMEOUT,
  interceptors: {
    requestInterceptors(config) {
      const token = localStorage.getItem('token');
      if (config.headers) {
        config.headers.Authorization =
          'Bearer ' + token?.slice(1, token.length - 1);
      }
      return config;
    },
    requestInterceptorsCatch(error) {
      return error;
    },
    responseInterceptors(res) {
      return res.data;
    },
    responseInterceptorsCatch(error) {
      return error;
    }
  }
});

export default hrRequest;
